import $ from 'jquery'
import { message } from 'antd';

(function () {
  let t = {};
  t.baseUrl = 'http://180.97.15.181:8899/';
  // t.baseUrl = 'http://192.168.30.29:8080/';
  // t.baseUrl = 'http://192.168.30.58:8080/';
  t.weChatUrl = 'http://180.97.15.181:8080/';
  // t.baseUrl = 'http://192.168.30.6:8080/'
  t.url = {

    login: t.baseUrl +'FakeSpider/login/login',
    getMessage: t.baseUrl+'FakeSpider/index/indexList',
    searchMessage: t.baseUrl+'FakeSpider/index/indexListByCondition',
    //详情页1
    searchId: t.baseUrl + 'FakeSpider/index/indexContentById',
    //详情页2
    searchId2: t.baseUrl + 'FakeSpider/index/findActionDataById',

    // 短信诈骗
    getfraudsms: t.baseUrl + 'FakeSpider/fraudMessage/findAllData',
    // 日期查询短信诈骗
    searchGetfraudsms: t.baseUrl + 'FakeSpider/fraudMessage/findAllDataByTime',
    // 导出短信诈
    exportExcelListByTime: t.baseUrl + 'FakeSpider/fraudMessage/exportExcelListByTime',
    // 导入
    importTable: t.baseUrl + 'FakeSpider/fraudMessage/import',

    blackId: t.baseUrl +'FakeSpider/index/isBlack',
    whiteId: t.baseUrl +'FakeSpider/index/isWhite',
    justBlack: t.baseUrl + 'FakeSpider/index/findBlackData',
    isUndetermined: t.baseUrl + 'FakeSpider/index/isUndetermined',
    findMessage: t.baseUrl + 'FakeSpider/index/findActionData',
    findActionData: t.baseUrl + 'FakeSpider/index/findActionDataByCondition',
    // 待处置列表
    waitchuzhi: t.baseUrl + 'FakeSpider/index/findWaitActionData',
    keyWords: t.baseUrl + 'FakeSpider/index/findKeyWordsList',
    // 处置人下拉
    chizhiList: t.baseUrl + 'FakeSpider/showData/findNowUser',
    // 关键字列表
    keyWordsAll: t.baseUrl + 'FakeSpider/key/queryKeyWordList ',
    // 新增关键字
    addNewWord: t.baseUrl + 'FakeSpider/key/addKeyWord',
    // 删除
    deleteKeyWords: t.baseUrl + 'FakeSpider/key/deleteKeyWordById',
    // 导出
    exportKeyWord: t.baseUrl + 'FakeSpider/key/exportKeyWordList',
    exportTable: t.baseUrl + 'FakeSpider/actionData/findActionDataByCondition',

    // 修改
    updateKeyWord: t.baseUrl + 'FakeSpider/key/updateKeyWord',
    // 修改密码
    changPassword: t.baseUrl + 'FakeSpider/login/updateUserPassword',
    // 输入疑似有害信息
    badMessage: t.baseUrl + 'FakeSpider/fakeUrl/addFakeUrl',
    // 非法域名模块查询接口
    illicitQuery: t.baseUrl + 'FakeSpider/domain/querybyCondition',
    //非法域名模块列表展示
    illicitList : t.baseUrl + 'FakeSpider/domain/showAll'
  };
  t.ajax = (obj, callback, fail) => {
    // console.log(JSON.stringify(obj.data))
    sessionStorage.setItem('loading', 'block')
    callback && typeof callback == 'function' ?
      $.ajax({
        url: obj.url,//可以不是本地域名
        type: obj.type,
        dataType: obj.json || 'json',  //jsonp格式访问
        jsonpCallback: 'jsonpCallback',  //获取数据的函数
        contentType: obj.contentType || 'application/json;charset=utf-8',
        data: obj.dataJsonp || JSON.stringify(obj.data) || '',
        success: function (data) {
          data && (!data.statusCode || data.statusCode == 200) ? callback(data) : message.error(data.message);
          sessionStorage.setItem('loading', 'none')
        },
        error: function (xml, parsererror) {
          // console.log(this.contentType)
          console.log(this.url)
          sessionStorage.setItem('loading', 'none')
          fail && typeof fail == 'function' ? fail() : ''
          message.error('请求失败')
        }
      },
      ) : console.log('请输入正确的回调类型')
  };

  t.login = (data, callback) => {
    t.ajax({
      url: t.url.login, type: 'post', data:data
    }, callback)
  };

  t.getfraudsms = (data, callback) => {
    t.ajax({
      url: t.url.getfraudsms, type: 'post', data:data
    }, callback)
  };

  t.searchGetfraudsms = (data, callback) => {
    t.ajax({
      url: t.url.searchGetfraudsms, type: 'post', data:data
    }, callback)
  };

  t.getMessage = (data, callback) => {
    t.ajax({
      url: t.url.getMessage, type: 'post', data:data
    }, callback)
  };

  t.searchMessage = (data, callback) => {
    t.ajax({
      url: t.url.searchMessage, type: 'post', data:data
    }, callback)
  };

  t.searchId = (data, callback) => {
    t.ajax({
      url: t.url.searchId, type: 'post', data:data
    }, callback)
  };

  t.waitchuzhi = (data, callback) => {
    t.ajax({
      url: t.url.waitchuzhi, type: 'post', data:data
    }, callback)
  };

  t.chizhiList = (callback) => {
    t.ajax({
      url: t.url.chizhiList, type: 'post',
    }, callback)
  };

  t.searchId2 = (data, callback) => {
    t.ajax({
      url: t.url.searchId2, type: 'post', data:data
    }, callback)
  };

  t.blackId = (data, callback) => {
    t.ajax({
      url: t.url.blackId, type: 'post', data:data
    }, callback)
  };

  t.whiteId = (data, callback) => {
    t.ajax({
      url: t.url.whiteId, type: 'post', data:data
    }, callback)
  };

  t.isUndetermined = (data, callback) => {
    t.ajax({
      url: t.url.isUndetermined, type: 'post', data:data
    }, callback)
  };

  t.justBlack = (data, callback) => {
    t.ajax({
      url: t.url.justBlack, type: 'post', data:data
    }, callback)
  };

  t.findMessage = (data, callback) => {
    t.ajax({
      url: t.url.findMessage, type: 'post', data:data
    }, callback)
  };

  t.findActionData = (data, callback) => {
    t.ajax({
      url: t.url.findActionData, type: 'post', data:data
    }, callback)
  };

  t.keyWords = (data, callback) => {
    t.ajax({
      url: t.url.keyWords, type: 'post', data:data
    }, callback)
  };

  t.keyWordsAll = (data, callback) => {
    t.ajax({
      url: t.url.keyWordsAll, type: 'post', data:data
    }, callback)
  };

  t.addNewWord = (data, callback) => {
    t.ajax({
      url: t.url.addNewWord, type: 'post', data:data
    }, callback)
  };

  t.deleteKeyWords = (data, callback) => {
    t.ajax({
      url: t.url.deleteKeyWords, type: 'post', data:data
    }, callback)
  };

  t.exportKeyWord = (callback) => {
    t.ajax({
      url: t.url.exportKeyWord,contentType: "application/x-www-form-urlencoded; charset=utf-8",dataType: 'html',type: "post",
    }, callback)
  };

  t.exportExcelListByTime = (data, callback) => {
    t.ajax({
      url: t.url.exportExcelListByTime, type: 'post', data:data
    }, callback)
  };

  // t.importTable = (callback) => {
  //   t.ajax({
  //     url: t.url.importTable, type: 'get'
  //   }, callback)
  // };

  t.exportTable = (data, callback) => {
    t.ajax({
      url: t.url.exportTable, type: 'post', data:data
    }, callback)
  };

  t.updateKeyWord = (data, callback) => {
    t.ajax({
      url: t.url.updateKeyWord, type: 'post', data:data
    }, callback)
  };
  
  t.changPassword = (data, callback) => {
    t.ajax({
      url: t.url.changPassword, type: 'post', data:data
    }, callback)
  };

  t.badMessage = (data, callback) => {
    t.ajax({
      url: t.url.badMessage, type: 'post', data:data
    }, callback)
  };
  t.illicitQuery = (data, callback) => {
    t.ajax({
      url: t.url.illicitQuery, type: 'post', data: data
    },callback)
  };
  t.illicitList = (data, callback) => {
    t.ajax({
      url: t.url.illicitList, type: 'post', data: data
    }, callback)
  }
  //存储
  t.setStore = (key, obj) => {
    localStorage.setItem(key, JSON.stringify(obj))
  };
  t.getStore = (key) => {
    return JSON.parse(localStorage.getItem(key))
  };

  //获取地址栏参数
  $.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
  };
  t.add0 = (m) => { return m < 10 ? '0' + m : m }
  t.unixTime = (shijianchuo) => {
    //shijianchuo是整数，否则要parseInt转换
    var time = shijianchuo?new Date(shijianchuo):new Date();
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + t.add0(m) + '-' + t.add0(d) + ' ' + t.add0(h) + ':' + t.add0(mm) + ':' + t.add0(s);
  }
  //获取时间
  t.getDate = (day, flag) => {
    var time = new Date();
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var dayTime = new Date(y, m - 1, 0);
    if (day && d < day) {
      d = dayTime + d - day;
      m = m - 1
    } else {
      day ? d = d - day : ''
    }
    return !flag ? y + '-' + t.add0(m) + '-' + t.add0(d) + ' 00:00:00' : y + '-' + t.add0(m) + '-' + t.add0(d) + ' 23:59:59'
  }
  t.substrTime = (time, start) => {
    return start && start == "start" ? time.split(' ')[0] + ' 00:00:00' : time.split(' ')[0] + ' 23:59:59'
  }
  t.setStore('error', { flag: true })
  window.u = t
})();

export default window.u


